<?php
include('../../config.php');
/**
 * Created by PhpStorm.
 * User: 明哲
 * Date: 2016/4/27
 * Time: 13:50
 */
session_start();
$username=$_SESSION['pipe_username'];
$startTime =  $_GET['startTime'];
$endTime =  $_GET['endTime'];
$productName =  $_GET['productName'];

$rows=$mysql->query("select `pipe_name` from `pipe` WHERE `pipe_username`='{$username}' limit 1");
$pipeName = $rows[0]['pipe_name'];

$page=$_GET['page'];
$number=$_GET['number'];

$min=$page*$number-$number;
$max=$number;
if($startTime !='' && $endTime !=''){
    if($productName != '全部产品' ){
        $rows=$mysql->query("select `time`,`product_name`,`pipe_name`,`active_user_ck`,`new_user_number`,`active_user`,`money_display` from `product_data` WHERE `status`=1 and `pipe_name`='{$pipeName}' and `product_name` like '%{$productName}%' and `time` BETWEEN '{$startTime}' and '{$endTime}' order by time DESC  limit {$min},{$max}");
        $count=$mysql->query("select COUNT(id) from `product_data` WHERE `status`=1 and `pipe_name`='{$pipeName}' and `product_name` like '%{$productName}%' and `time` BETWEEN '{$startTime}' and '{$endTime}'");
    }else{
        $rows=$mysql->query("select `time`,`product_name`,`pipe_name`,`active_user_ck`,`new_user_number`,`active_user`,`money_display` from `product_data` WHERE `status`=1 and `pipe_name`='{$pipeName}' and `time` BETWEEN '{$startTime}' and '{$endTime}' order by time DESC limit {$min},{$max}");
        $count=$mysql->query("select COUNT(id) from `product_data` WHERE `status`=1 and `pipe_name`='{$pipeName}' and `time` BETWEEN '{$startTime}' and '{$endTime}'");
    }
    $num = 0;
    foreach($rows as $row){
        $num += $row['active_user_ck'];
}
//    var_dump($num);
    $rs['count'] = $count[0]["COUNT(id)"];
    $rs['data'] = $rows;
    $rs['current_page'] = $page;
    $rs['num'] = $num;
    $rs = json_encode($rs);
    echo $rs;
}